package cn.cms.controller;

import cn.cms.dao.PageDao;
import cn.cms.service.SysLogService;
import org.perf4j.StopWatch;
import org.perf4j.slf4j.Slf4JStopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "systemLog")
public class SysLogController extends AbstractController {

    @Autowired
    private SysLogService sysLogService;

    @RequestMapping(value = "list")
    public String list(HttpServletRequest request, Model model, PageDao pageDao, String temple, String keyWords, String type, String startTime, String endTime) {

        pageDao.setQueryCondition(super.getQueryCondition(request));
        pageDao.setDivId(super.getDivId(request));
        pageDao.setResult(sysLogService.getListPage(pageDao, temple, keyWords, type, startTime, endTime));
        model.addAttribute("pages", pageDao);

        return "syslog/list";
    }

    @RequestMapping(value = "toplist")
    public String list(Model model) {
        PageDao pageDao = new PageDao();
        pageDao.setPageSize(10);
        pageDao.setResult(sysLogService.getListPage(pageDao, null, null, null, null, null));
        model.addAttribute("logs", pageDao);
        return "syslog/toplist";
    }

    /**
     * 列表头
     */
    @RequestMapping(value = "page", method = RequestMethod.POST)
    public String page() {
        return "syslog/page";
    }
}
